#include "modifyuserdialog.h"
#include "ui_modifyuserdialog.h"

ModifyUserDialog::ModifyUserDialog(const QString &username, const QString &password, const QString &role, QWidget *parent)
    : QDialog(parent), ui(new Ui::ModifyUserDialog)
{
    ui->setupUi(this);

    // 设置用户名和密码的输入框
    usernameEdit = ui->lineEditUsername;
    passwordEdit = ui->lineEditPassword;

    // 设置角色下拉框
    roleComboBox = ui->comboBoxRole;
    roleComboBox->addItem("系统管理员");
    roleComboBox->addItem("业务管理员");
    roleComboBox->addItem("用户");

    // 填充现有数据
    usernameEdit->setText(username);
    passwordEdit->setText(password);

    int roleIndex = roleComboBox->findText(role);
    if (roleIndex != -1) {
        roleComboBox->setCurrentIndex(roleIndex);
    }
}

ModifyUserDialog::~ModifyUserDialog()
{
    delete ui;
}

QString ModifyUserDialog::getUsername() const
{
    return usernameEdit->text();
}

QString ModifyUserDialog::getPassword() const
{
    return passwordEdit->text();
}

QString ModifyUserDialog::getRole() const
{
    return roleComboBox->currentText();
}

void ModifyUserDialog::on_pushButtonConfirm_clicked()
{
    accept();
}

void ModifyUserDialog::on_pushButtonExit_clicked()
{
    close();
}
